<?php
/**
 * Created by PhpStorm.
 * User: zhuanggit
 * Date: 2019/2/28
 * Time: 14:53
 */
namespace App\Observers;

use App\Models\Member;
use Illuminate\Support\Facades\DB;

class MemberObserver
{
    public function deleted(Member $member)
    {
        \DB::table('meets')->where('member_id', $member->id)->delete();
//        $meet->member->increment('share_count', 1);
    }
    public function updated(Member $member)
    {
    if($member->state==1){
        if($member->username==null||$member->password==null){}
        else{
            DB::table('admin_user_permissions')
                ->updateOrInsert(
                    ['user_id' => $member->id,'permission_id'=>6],
                    ['user_id' => $member->id, 'permission_id' => 6]
                );
            DB::table('admin_role_users')
                ->updateOrInsert(
                    ['user_id' => $member->id,'role_id'=>2],
                    ['user_id' => $member->id, 'role_id' => 2]
                );
            DB::table('admin_users')
                ->updateOrInsert(
                    ['member_id' => $member->id],
                    ['id'=>$member->id,'member_id' => $member->id, 'username' => $member->username,'password' => bcrypt($member->password),'name' => $member->name]
                );
        }
        }

    }
}
